package com.ieng.ormosia.connect.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ieng.ormosia.common.vo.PageData;
import com.ieng.ormosia.connect.mapper.UserMapper;
import com.ieng.ormosia.connect.model.User;
import com.ieng.ormosia.connect.service.UserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
	@Resource
	private UserMapper userMapper;

	@Override
	public PageData<User> getUserAll(int page, int size) {
		PageHelper.startPage(page, size);
		return paging(userMapper.selectAll());
	}

	@Override
	public PageData<User> getUserHashQ(int page, int size, User record) {
		PageHelper.startPage(page, size);
		return paging(userMapper.select(record));
	}

	@Override
	public PageData<User> getUserDelAll(int page, int size) {
		PageHelper.startPage(page, size);
		return paging(userMapper.selectDelList());
	}

	@Override
	public User getUser(Long id) {
		return null;
	}

	@Transactional
	@Override
	public void addUser(User user) {

	}

	@Transactional
	@Override
	public void editUser(User user) {

	}

	@Transactional
	@Override
	public void removeRole(Long id) {

	}

	@Transactional
	@Override
	public void delUser(Long id) {

	}

	private PageData<User> paging(List<User> list){
		PageInfo<User> pageInfo = new PageInfo<>(list);
		PageData<User> data = new PageData<>(pageInfo.getList());
		data.setPage(pageInfo.getPageNum());
		data.setTotal(pageInfo.getTotal());
		data.setSize(pageInfo.getPageSize());
		return data;
	}
}
